package com.myebills.ebpsfrontend.cust.controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Concrete servlet class used to display any input form.
 * <p>Call servlet with query parameter "urlJSP" set to URL of JSP that contains form.
 * <p>Servlet binds an empty EbppxInputFieldMessages object to request if none exists in order to
 * facilitate coding of the form JSP,
 * which can now assume that an EbppxInputFieldMessages bean instance exists in request scope.
 */
public class EbppxDisplayFormServlet extends EbppxTransactionServlet {
        /**
         * If request does not have attribute "EbppxInputFieldMessages", create and add it to request.
         * Dispatch to form JSP.
         */
        protected final void doTransaction(
            HttpServletRequest req,
            HttpServletResponse res)
            throws ServletException, java.io.IOException {

            if (null == req.getAttribute(EbppxInputFieldMessages.REQUEST_ATTRIBUTE_NAME)) {
                req.setAttribute(
                        EbppxInputFieldMessages.REQUEST_ATTRIBUTE_NAME,
                        new EbppxInputFieldMessages()
                        );
            }

            forwardToMappedUrl(req, res, EbppxConstants.URL_JSP_PARAM, getFormDataQueryParameters(req));
        }

        /**
         * Return the current form data as a concatenated list of query parameters.
         */
        protected String getFormDataQueryParameters(HttpServletRequest req)
            throws ServletException {
            return "";
        }

}